<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
var minimumTime = function (time, totalTrips) {
    // 找到最小值 left
    let left = Math.min(...time);
    // 找到最大值 right 也就是最小值 min * totalTrips
    let right = totalTrips * left;
    // 使用二分查找筛选符合的条件
    while (left < right) {
        let middle = left + Math.floor((right - left) /2);
        let trips = 0;
        // 遍历每个车次需要完成的时间
        for (const t of time) {
            // 计算可以完成的旅途数
            trips += Math.floor(middle / t);
            if (trips >= totalTrips) break;
        }
        
        // 如果超过 totalTrips，缩小到前半部分继续向左查找，反之缩小到后半部分向右查找
        if (trips >= totalTrips) {
            right = middle;
        } else {
            left = middle + 1;
        }
    }

    return left;
};
console.log(minimumTime([1,2,3],[5]));
  </script>
</body>
</html>